<?php
/**
if (!class_exists('EventManager_Resource_Adres')) {
	require_once dirname(__FILE__) . '/Adres.php';
}
*/

if (!class_exists('EventManager_Resource_Event_Interface')) {
	require_once dirname(__FILE__) . '/Event/Interface.php';
}

/**
@todo move all the methods to the right resources 
*/
class EventManager_Resource_Event extends SF_Model_Resource_Db_Table_Abstract
implements EventManager_Resource_Event_Interface{
	/**
	 *
	 * @var string table name
	 */
	protected $_name = 'events';
	/**
	 *
	 * @var string primary Id
	 */
	protected $_primary = 'evt_id';
	/**
	 * @var string row Class
	 */
	protected $_rowClass = 'EventManager_Resource_Event_Item';

	
	
	/**
	 * (non-PHPdoc)
	 * @see modules/eventManager/models/resources/Event/EventManager_Resource_Event_Interface#getEventById($id)
	 */
	public function getEventById($id)
	{
		return $this->find($id)->current();
	}
	/**
	 * (non-PHPdoc)
	 * @see modules/eventManager/models/resources/Event/EventManager_Resource_Event_Interface#getAllEvents($startDate, $endDate)
	 */
	public function getAllEvents($startdate =null, $enddate =null,$paged){
		$select = $this->select();
		// @todo for later implementation: implement optional prameters.
		// @todo functionality for ordering de resultset
		if(!isset($paged)){
			$paged = 1;
		}

		if(null !== $paged){
			$adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
				
			$count = clone $select;
			$count->reset(Zend_Db_Select::COLUMNS);
			$count->reset(Zend_Db_Select::FROM);
			$count->from(
					'events',
			new Zend_Db_Expr(
						'COUNT(*) AS `zend_paginator_row_count`'
						)
						);
						$adapter->setRowCount($count);

						$paginator = new Zend_Paginator($adapter);
						$paginator->setItemCountPerPage(10)
						->setCurrentPageNumber((int)$paged);
						return $paginator;
		}
		return $this->fetchAll($select);
			
	}





}
